package com.neusoft.nepa.controller;

import com.neusoft.nepa.controller.BackgroundPane;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class AdminViewControllers implements Initializable {
    @FXML
    private Label userNameLabel;
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        Platform.runLater(this::updateLabel);
        Platform.runLater(() -> {
            if (userNameLabel != null) {
                updateLabel();
            } else {
                System.err.println("userNameLabel 未正确注入！");
            }
        });
    }
    private void updateLabel()
    {
        Stage stage = (Stage)userNameLabel.getScene().getWindow();
        userNameLabel.setText("当前用户:"+stage.getProperties().get("userName"));
    }
    @FXML
    private void logOut(ActionEvent event) throws IOException {
        Stage stage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
        stage.getProperties().remove("userName");
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/neusoft/nepa/view/AdminLoginView.fxml"));
        Parent fxmlContent = fxmlLoader.load();
        BackgroundPane backgroundPane = new BackgroundPane();
        backgroundPane.getChildren().add(fxmlContent);
        fxmlContent.setStyle("-fx-background-color: transparent;");
        Scene newScene = new Scene(backgroundPane, 960, 540);
        stage.setTitle("NorthEast Software Corporation Public Supervisor Platform Manage System");
        stage.setScene(newScene);
        stage.show();
    }
    @FXML
    public void superviseList(ActionEvent event) throws IOException {
        Stage stage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/neusoft/nepa/view/PublicSuperviseList.fxml"));
        Parent parent = fxmlLoader.load();
        Scene newScene = new Scene(parent, 960, 540);
        stage.setTitle("NorthEast Software Corporation Public Supervisor Platform Manage System");
        stage.setScene(newScene);
        stage.show();
    }
    public void changeToAQI(ActionEvent event) throws IOException {
        Stage stage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/neusoft/nepa/view/AQIConfigList.fxml"));
        Parent parent = fxmlLoader.load();
        Scene newScene = new Scene(parent, 960, 540);
        stage.setTitle("NorthEast Software Corporation Public Supervisor Platform Manage System");
        stage.setScene(newScene);
        stage.show();
    }
    public void changeToProvinceGroupInspection(ActionEvent event) throws IOException {
        Stage stage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/neusoft/nepa/view/ProvinceGroupInspectionView.fxml"));
        Parent parent = fxmlLoader.load();
        Scene newScene = new Scene(parent, 960, 540);
        stage.setTitle("NorthEast Software Corporation Public Supervisor Platform Manage System");
        stage.setScene(newScene);
        stage.show();
    }
    @FXML
    private void changePassword(ActionEvent event) throws IOException {
        Stage stage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/neusoft/nepa/view/ChangePassword.fxml"));
        Parent parent = fxmlLoader.load();
        Scene newScene = new Scene(parent, 960, 540);
        stage.setTitle("Check for information");
        stage.setResizable(false);
        stage.setScene(newScene);
        stage.show();
    }
}
